/**
 * @author Fedorchenko Alexander <admin@xepec.ru>
 * @copyright (c) Fedorchenko Alexander <admin@xepec.ru>
 */

//alert('"Debug message" version: 0.1γ');

function getXmlHttp()
{
	var xmlhttp
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e1) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}
function setCookie (name, value, expires, path, domain, secure)
{
      document.cookie = name + "=" + escape(value) +((expires) ? "; expires=" + expires : "") +((path) ? "; path=" + path : "") +((domain) ? "; domain=" + domain : "") +((secure) ? "; secure" : "");
}

function login()
{	
	var input1 = document.getElementById("nic");
	var nic = input1.value;
	nic = nic.toLowerCase();
	
	var input2 = document.getElementById("pass");
	var pass = input2.value;
	
	var hex_md5_pass;
	var date_now = new Date();
	date_now.setHours(date_now.getHours() + 3);
	var time_end = date_now.toString();
	//alert(time_end);

	
	var jid = nic + '@' + 'jabber.xepec.ru' + '/'+ 'Home-' + Math.round(Math.random()*100000);
	var aaa1 = str_md5(nic + ':jabber.xepec.ru:' + pass);

	hex_md5_pass = hex_md5(pass);

	//alert(jid);
	//alert(hex_md5_pass);
	//alert('aaa1');

	setCookie("xepec_pass", hex_md5_pass, time_end );
	setCookie("xepec_nic", nic, time_end );
	setCookie("xepec_jabber", aaa1, time_end);
	

	self.location.href = 'auth.pl';
	//self.window.open('auth.php');
}

//location.href = location.href + "#dasf=s";
function reload_captcha()
{
	var div_captcha = document.getElementById("captcha_img");

	//var znachenie = captcha.src;
	
	var req = getXmlHttp(); 
	req.open('GET', '/core/reload_captcha.pl?act=new', true);
	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			if(req.status == 200)
			{
				
				if (req.responseText != '1')
				{
					//znachenie = req.responseText;
					div_captcha.innerHTML = '<img src="' + req.responseText + '" /><span onclick="reload_captcha();" title="Перегрузить" ><img src="/image/reload.gif" style="border:0;" width="12px" height="13px" alt="Перегрузить" /></span>';
					document.getElementById("captcha").value = "";
				}
				else 
				{
					//div_message.innerHTML = '<span style="color: green">Имя свободно</span>';
				}
				
			}
		}
	}
	req.send(null)
}
